#include "GY_GraphicsWideTextItem.h"
#include <QPen>
#include <QPainter>
#include <QDebug>
#include <QtMath>
#include <QMetaEnum>
#include <QFontDatabase>
#include <QDir>

GY_GraphicsWideTextItem::GY_GraphicsWideTextItem(const QString &guid, QGraphicsItem *parent)
    : GY_BasicsGraphicsObject(guid,this,parent)
{
    //图元类型
    GY_Object::setUserData(GY_ENUM::ClassType,QVariant("WideText"));
    this->setTransform(QTransform::fromScale(1,-1));
    initializationPropertyInfo();
    updataPen();
    updataBrush();
    updateDraw();
    this->setPen(QColor(Qt::green));
    this->setEditPointF("Point",QPointF(50,20));
    this->setCenterPointF(m_PropertyInfoMap["Position"].propertyValue.toPointF());
}

GY_GraphicsWideTextItem::GY_GraphicsWideTextItem(const QString &guid, qreal x, qreal y, QGraphicsItem *parent)
    : GY_BasicsGraphicsObject(guid,this,parent)
{
    //图元类型
    GY_Object::setUserData(GY_ENUM::ClassType,QVariant("WideText"));
    this->setTransform(QTransform::fromScale(1,-1));
    initializationPropertyInfo();
    updataPen();
    updataBrush();
    QPointF position(x,y);
    m_PropertyInfoMap["Position"].propertyValue = position;
    updateDraw();
    this->setEditPointF("Point",QPointF(50,20));
    this->setCenterPointF(position);
}

bool GY_GraphicsWideTextItem::updateSize(const QString &name, const QVariant &value)
{
    if(!value.canConvert<QPointF>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue=value;
    //更新Size点，Point点为中心点加Size点再设置编辑点
    this->setEditPointF("Point",this->mapFromScene(value.toPointF()+this->mapToScene(m_PropertyInfoMap["Position"].propertyValue.toPointF())));
    updateDraw();
    return true;
}

void GY_GraphicsWideTextItem::updataPen()
{
    QPen pen = this->pen();
    if(!m_PropertyInfoMap["IsOutlined"].propertyValue.value<bool>())
    {
        pen.setStyle(Qt::NoPen);
        this->setPen(pen);
        return;
    }
    //继承上层属性
    QMap<QString, GY_PropertyInfo> inheritAttributes;
    if(m_PropertyInfoMap["PenAttributes"].propertyValue.toBool()) {
        //获取最上层继承属性
        inheritAttributes = getInheritAttributes("PenAttributes", this);
        //最上层继承属性为true说明不需要使用继承属性，使用原属性
        if(inheritAttributes["PenAttributes"].propertyValue.toBool() == true) {
            inheritAttributes = m_PropertyInfoMap;
        }
    }else {
        inheritAttributes = m_PropertyInfoMap;
    }
    //笔的颜色
    QColor penColor = inheritAttributes["PenColor"].propertyValue.value<QColor>();
    pen.setColor(penColor);
    double thickness = m_PropertyInfoMap["Thickness"].propertyValue.value<double>();
    if(thickness > 10) {
        thickness = 10;
    }else if(thickness < 0.5) {
        thickness = 0.5;
    }
    pen.setWidthF(thickness*0.1);
    pen.setStyle((Qt::SolidLine));
    pen.setJoinStyle((Qt::MiterJoin));
    pen.setCapStyle((Qt::FlatCap));

    this->setPen(pen);
}

void GY_GraphicsWideTextItem::updataBrush()
{
    QBrush brush = this->brush();
    if(!m_PropertyInfoMap["IsFilled"].propertyValue.value<bool>())
    {
        brush.setStyle(Qt::NoBrush);
        this->setBrush(brush);
        return;
    }

    //继承上层属性
    QMap<QString, GY_PropertyInfo> inheritAttributes;
    if(m_PropertyInfoMap["FillAttributes"].propertyValue.toBool()) {
        //获取最上层继承属性
        inheritAttributes = getInheritAttributes("FillAttributes", this);
        //最上层继承属性为true说明不需要使用继承属性，使用原属性
        if(inheritAttributes["FillAttributes"].propertyValue.toBool() == true) {
            inheritAttributes = m_PropertyInfoMap;
        }
    }else {
        inheritAttributes = m_PropertyInfoMap;
    }
    QColor brushColor = inheritAttributes["FillColor"].propertyValue.value<QColor>();
    brush.setStyle(Qt::SolidPattern);
    brush.setColor(brushColor);
    this->setBrush(brush);
}

void GY_GraphicsWideTextItem::initializationPropertyInfo()
{
    //位置
    GY_PropertyInfo positonPropertyInfo(this);
    positonPropertyInfo.propertyName="Position";
    positonPropertyInfo.propertyValue=QPointF(0,0);
    positonPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updateCirlePoint;
    positonPropertyInfo.propertyType=PropertyType::PointPropertyType;
    positonPropertyInfo.updateType=PropertyUpdateType::PointOfRelative|PropertyUpdateType::MoveUpdate|PropertyUpdateType::Update;
    m_PropertyInfoMap.insert(positonPropertyInfo.propertyName,positonPropertyInfo);
    m_PropertyInfoMap[positonPropertyInfo.propertyName].setConnect();
    //更新点位置
    GY_PropertyInfo sizePropertyInfo(this);
    sizePropertyInfo.propertyName="Size";
    sizePropertyInfo.propertyValue=QPointF(0,0);
    sizePropertyInfo.updateType = Update|OrdinaryAttributes;
    sizePropertyInfo.propertyType = PointPropertyType;
    sizePropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updateSize;
    m_PropertyInfoMap.insert(sizePropertyInfo.propertyName,sizePropertyInfo);
    m_PropertyInfoMap[sizePropertyInfo.propertyName].setConnect();

    GY_PropertyInfo pointPropertyInfo(this);
    pointPropertyInfo.propertyName="Point";
    pointPropertyInfo.propertyValue=QPointF(0,0);
    pointPropertyInfo.updateType = NotUpdate;
    pointPropertyInfo.propertyType = PointPropertyType;
    pointPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updatePoint;
    m_PropertyInfoMap.insert(pointPropertyInfo.propertyName,pointPropertyInfo);
    m_PropertyInfoMap[pointPropertyInfo.propertyName].setConnect();

    //文本数据
    GY_PropertyInfo DataStringPropertyInfo(this);
    DataStringPropertyInfo.propertyName="DataString";
    DataStringPropertyInfo.propertyValue="ABC 123";
    DataStringPropertyInfo.updateType = Update|OrdinaryAttributes;
    DataStringPropertyInfo.propertyType = QStringPropertyType;
    DataStringPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updateDataString;
    m_PropertyInfoMap.insert(DataStringPropertyInfo.propertyName,DataStringPropertyInfo);
    m_PropertyInfoMap[ DataStringPropertyInfo.propertyName].setConnect();

    //文本长度
    GY_PropertyInfo DataStringCapacityPropertyInfo(this);
    DataStringCapacityPropertyInfo.propertyName="DataString.Capacity";
    DataStringCapacityPropertyInfo.propertyValue=10;
    DataStringCapacityPropertyInfo.updateType = Update|OrdinaryAttributes;
    DataStringCapacityPropertyInfo.propertyType = IntPropertyType;
    DataStringCapacityPropertyInfo.updatePropertyFun=(GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updateDataStringCapacity;
    m_PropertyInfoMap.insert(DataStringCapacityPropertyInfo.propertyName,DataStringCapacityPropertyInfo);
    m_PropertyInfoMap[DataStringCapacityPropertyInfo.propertyName].setConnect();

    //加粗
    GY_PropertyInfo IsBold(this);
    IsBold.propertyName = "IsBold";
    IsBold.propertyValue = false;
    IsBold.updateType = Update|OrdinaryAttributes;
    IsBold.propertyType = BoolPropertyType;
    IsBold.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updateIsBold;
    m_PropertyInfoMap.insert("IsBold",IsBold);
    m_PropertyInfoMap[IsBold.propertyName].setConnect();

    //倾斜
    GY_PropertyInfo IsItalic(this);
    IsItalic.propertyName = "IsItalic";
    IsItalic.propertyValue = false;
    IsItalic.updateType = Update|OrdinaryAttributes;
    IsItalic.propertyType = BoolPropertyType;
    IsItalic.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updateIsItalic;
    m_PropertyInfoMap.insert("IsItalic",IsItalic);
    m_PropertyInfoMap[IsItalic.propertyName].setConnect();

    //字体大小
    GY_PropertyInfo PointSize(this);
    PointSize.propertyName = "PointSize";
    PointSize.propertyValue = 12;
    PointSize.updateType = Update|OrdinaryAttributes;
    PointSize.propertyType = IntPropertyType;
    PointSize.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updatePointSize;
    m_PropertyInfoMap.insert("PointSize",PointSize);
    m_PropertyInfoMap[PointSize.propertyName].setConnect();

    //字体厚度
    GY_PropertyInfo Thickness(this);
    Thickness.propertyName = "Thickness";
    Thickness.propertyValue = 2.0;
    Thickness.updateType = Update|OrdinaryAttributes;
    Thickness.propertyType = DoublePropertyType;
    Thickness.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updateThickness;
    m_PropertyInfoMap.insert("Thickness",Thickness);
    m_PropertyInfoMap[Thickness.propertyName].setConnect();

    //对齐方式
    GY_PropertyInfo Alignment(this);
    Alignment.propertyName = "Alignment";
    Alignment.propertyValue = "LEFT";
    Alignment.updateType = Update|OrdinaryAttributes;
    Alignment.propertyType = TextAlignmentPropertyType;
    Alignment.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updateAlignment;
    m_PropertyInfoMap.insert("Alignment",Alignment);
    m_PropertyInfoMap[Alignment.propertyName].setConnect();

    //字体格式
    GY_PropertyInfo FontId(this);
    FontId.propertyName = "FontId";
    FontId.propertyValue = "Arial";
    FontId.updateType = Update|OrdinaryAttributes;
    FontId.propertyType = FontIdPropertyType;
    FontId.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updateFontId;
    m_PropertyInfoMap.insert("FontId",FontId);
    m_PropertyInfoMap[FontId.propertyName].setConnect();

    /*
     *LineStyle属性的数据
     * QVector<qreal>中index(0)是Qt::PenCapStyle、Qt::PenJoinStyle与Qt::PenStyle的组合,index(1)为线条粗细，之后是自定义钢笔样式的数据 */
    QVector<qreal> varStyle;
    int style = Qt::SquareCap|Qt::BevelJoin|Qt::CustomDashLine;
    varStyle<<style<<2<<3<<2<<4<<5<<6<<7;

    int gradientSpread = QGradient::PadSpread;//指定如何填充渐变之外的区域
    QColor colorStart = QColor(0,255,0);//开始颜色
    QColor colorStop = QColor(0,0,255);//结束颜色
    int gradientType = QGradient::LinearGradient;//指定渐变的类型
    QPointF pointFStart = QPointF(0,0);//开始的坐标或中心点坐标
    QPointF pointFStop = QPointF(1,1);//结束的坐标或径向梯度的焦点坐标
    qreal centerRadius = 100;//中心半径
    qreal focalRadius = 100;//径向梯度的焦点半径
    QVector<qreal> varGradientStyle;
    varGradientStyle<<gradientSpread<<colorStart.rgb()<<colorStop.rgb()<<gradientType<<pointFStart.x()
                   <<pointFStart.y()<<pointFStop.x()<<pointFStop.y()<<centerRadius<<focalRadius;

    GY_PropertyInfo ObjectName(this);
    ObjectName.propertyName = "ObjectName";
    ObjectName.propertyValue = QString();
    ObjectName.updateType = Update|OrdinaryAttributes;
    ObjectName.propertyType = QStringPropertyType;
    ObjectName.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updateObjectName;
    m_PropertyInfoMap.insert("ObjectName",ObjectName);
    m_PropertyInfoMap[ObjectName.propertyName].setConnect();

    GY_PropertyInfo PenAttributes(this);
    PenAttributes.propertyName = "PenAttributes";
    PenAttributes.propertyValue = false;
    PenAttributes.updateType = Update|OrdinaryAttributes;
    PenAttributes.propertyType = BoolPropertyType;
    PenAttributes.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updatePenAttributes;
    m_PropertyInfoMap.insert("PenAttributes",PenAttributes);
    m_PropertyInfoMap[PenAttributes.propertyName].setConnect();

    GY_PropertyInfo IsOutLined(this);
    IsOutLined.propertyName = "IsOutlined";
    IsOutLined.propertyValue = true;
    IsOutLined.updateType = Update|OrdinaryAttributes;
    IsOutLined.propertyType = BoolPropertyType;
    IsOutLined.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updateIsOutLined;
    m_PropertyInfoMap.insert("IsOutlined",IsOutLined);
    m_PropertyInfoMap[IsOutLined.propertyName].setConnect();

    GY_PropertyInfo FillAttributes(this);
    FillAttributes.propertyName = "FillAttributes";
    FillAttributes.propertyValue = false;
    FillAttributes.updateType = Update|OrdinaryAttributes;
    FillAttributes.propertyType = BoolPropertyType;
    FillAttributes.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updateFillAttributes;
    m_PropertyInfoMap.insert("FillAttributes",FillAttributes);
    m_PropertyInfoMap[FillAttributes.propertyName].setConnect();

    GY_PropertyInfo PenColor(this);
    PenColor.propertyName = "PenColor";
    PenColor.propertyValue = QColor();
    PenColor.updateType = Update|OrdinaryAttributes;
    PenColor.propertyType = ColorPropertyType;
    PenColor.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updatePenColor;
    m_PropertyInfoMap.insert("PenColor",PenColor);
    m_PropertyInfoMap[PenColor.propertyName].setConnect();

    GY_PropertyInfo IsFilled(this);
    IsFilled.propertyName = "IsFilled";
    IsFilled.propertyValue = true;
    IsFilled.updateType = Update|OrdinaryAttributes;
    IsFilled.propertyType = BoolPropertyType;
    IsFilled.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updateIsFilled;
    m_PropertyInfoMap.insert("IsFilled",IsFilled);
    m_PropertyInfoMap[IsFilled.propertyName].setConnect();

    GY_PropertyInfo FillColor(this);
    FillColor.propertyName = "FillColor";
    FillColor.propertyValue = QColor();
    FillColor.updateType = Update|OrdinaryAttributes;
    FillColor.propertyType = ColorPropertyType;
    FillColor.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updateFillColor;
    m_PropertyInfoMap.insert(FillColor.propertyName,FillColor);
    m_PropertyInfoMap[FillColor.propertyName].setConnect();

    GY_PropertyInfo IsVisible(this);
    IsVisible.propertyName = "IsVisible";
    IsVisible.propertyValue = true;
    IsVisible.updateType = Update|OrdinaryAttributes;
    IsVisible.propertyType = BoolPropertyType;
    IsVisible.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updateIsVisible;
    m_PropertyInfoMap.insert("IsVisible",IsVisible);
    m_PropertyInfoMap[IsVisible.propertyName].setConnect();

    GY_PropertyInfo IsAntialiased(this);
    IsAntialiased.propertyName = "IsAntialiased";
    IsAntialiased.propertyValue = false;
    IsAntialiased.updateType = Update|OrdinaryAttributes;
    IsAntialiased.propertyType = BoolPropertyType;
    IsAntialiased.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updateIsAntialiased;
    m_PropertyInfoMap.insert("IsAntialiased",IsAntialiased);
    m_PropertyInfoMap[IsAntialiased.propertyName].setConnect();

    GY_PropertyInfo IsStrikethrough(this);
    IsStrikethrough.propertyName = "IsStrikethrough";
    IsStrikethrough.propertyValue = false;
    IsStrikethrough.updateType = Update|OrdinaryAttributes;
    IsStrikethrough.propertyType = BoolPropertyType;
    IsStrikethrough.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updateIsStrikethrough;
    m_PropertyInfoMap.insert("IsStrikethrough",IsStrikethrough);
    m_PropertyInfoMap[IsStrikethrough.propertyName].setConnect();

    GY_PropertyInfo IsUnderlined(this);
    IsUnderlined.propertyName = "IsUnderlined";
    IsUnderlined.propertyValue = false;
    IsUnderlined.updateType = Update|OrdinaryAttributes;
    IsUnderlined.propertyType = BoolPropertyType;
    IsUnderlined.updatePropertyFun = (GY_PropertyInfo::UpdatePropertyFun)&GY_GraphicsWideTextItem::updateIsUnderlined;
    m_PropertyInfoMap.insert("IsUnderlined",IsUnderlined);
    m_PropertyInfoMap[IsUnderlined.propertyName].setConnect();

}

void GY_GraphicsWideTextItem::updateDraw()
{
    QPainterPath path;
    QPointF point = precalculatedPosition();
    path.addText(point, m_Font, m_PropertyInfoMap["DataString"].propertyValue.toString());
    this->setPath(path);
}

bool GY_GraphicsWideTextItem::updateCirlePoint(const QString &name, const QVariant &value)
{
    if(!value.canConvert<QPointF>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue=this->mapFromScene(value.toPointF());
    this->setCenterPointF(this->mapFromScene(value.toPointF()));
    //中心点移动Point点也要移动
    this->setEditPointF("Point",this->mapFromScene(value.toPointF()+m_PropertyInfoMap["Size"].propertyValue.toPointF()));
    updateDraw();
    return true;
}

bool GY_GraphicsWideTextItem::updateDataString(const QString &name, const QVariant &value)
{
    if(!value.canConvert<QString>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue=value;
    if(value.toString().length() > m_PropertyInfoMap["DataString.Capacity"].propertyValue.toInt()) {
        m_PropertyInfoMap["DataString.Capacity"].propertyValue = value.toString().length();
    }
    updateDraw();
    return true;
}

bool GY_GraphicsWideTextItem::updateDataStringCapacity(const QString &name, const QVariant &value)
{
    if(!value.canConvert<int>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue=value;
    if(m_PropertyInfoMap["DataString"].propertyValue.toString().length() > value.toInt()) {
        m_PropertyInfoMap["DataString"].propertyValue = m_PropertyInfoMap["DataString"].propertyValue.toString().mid(0, value.toInt());
    }
    updateDraw();
    return true;
}

bool GY_GraphicsWideTextItem::updatePoint(const QString &name, const QVariant &value)
{
    if(!value.canConvert<QPointF>())
    {
        return false;
    }
    //相对中心点Size用鼠标点减去中心点获取
    QPointF pf=this->mapFromScene(value.value<QPointF>())-(m_PropertyInfoMap["Position"].propertyValue.toPointF());
    //文本上下翻转，点Y值取反才符合坐标系规则
    pf.setY(-pf.y());
    m_PropertyInfoMap["Size"].propertyValue = pf;
    updateDraw();
    this->setEditPointF(name,this->mapFromScene(value.value<QPointF>()));
    return true;
}

bool GY_GraphicsWideTextItem::updateIsBold(const QString &name, const QVariant &value)
{
    if(!value.canConvert<bool>())
    {
        return false;
    }
    bool isBold = value.value<bool>();
    m_PropertyInfoMap[name].propertyValue=isBold;
    m_Font.setBold(isBold);
    updateDraw();
    return true;
}

bool GY_GraphicsWideTextItem::updateIsItalic(const QString &name, const QVariant &value)
{
    if(!value.canConvert<bool>())
    {
        return false;
    }
    bool isItalic = value.value<bool>();
    m_PropertyInfoMap[name].propertyValue=isItalic;
    m_Font.setItalic(isItalic);
    updateDraw();
    return true;
}

bool GY_GraphicsWideTextItem::updatePointSize(const QString &name, const QVariant &value)
{
    if(!value.canConvert<int>())
    {
        return false;
    }
    int pointSize = value.value<int>();
    m_PropertyInfoMap[name].propertyValue=pointSize;
    m_Font.setPointSize(pointSize);
    updateDraw();
    return true;
}

bool GY_GraphicsWideTextItem::updateThickness(const QString &name, const QVariant &value)
{
    if(!value.canConvert<double>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue=value;
//    m_Font.setPixelSize(100);
    updateDraw();
    return true;
}

bool GY_GraphicsWideTextItem::updateAlignment(const QString &name, const QVariant &value)
{
    if(!value.canConvert<QString>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue=value;
    updateDraw();
    return true;
}

bool GY_GraphicsWideTextItem::updateIsStrikethrough(const QString &name, const QVariant &value)
{
    if(!value.canConvert<bool>())
    {
        return false;
    }
    bool IsStrikethrough = value.value<bool>();
    m_PropertyInfoMap[name].propertyValue=IsStrikethrough;
    m_Font.setStrikeOut(IsStrikethrough);
    updateDraw();
    return true;
}

bool GY_GraphicsWideTextItem::updateIsUnderlined(const QString &name, const QVariant &value)
{
    if(!value.canConvert<bool>())
    {
        return false;
    }
    bool IsUnderlined = value.value<bool>();
    m_PropertyInfoMap[name].propertyValue=IsUnderlined;
    m_Font.setUnderline(IsUnderlined);
    updateDraw();
    return true;
}

bool GY_GraphicsWideTextItem::updateFontId(const QString &name, const QVariant &value)
{
    if(!value.canConvert<QString>())
    {
        return false;
    }
    m_PropertyInfoMap[name].propertyValue = value;
    QDir dir("C:/Windows/Fonts");
    QString filePath = dir.absoluteFilePath(value.toString());
    int fontId = QFontDatabase::addApplicationFont(filePath);
    QStringList fontFamilies = QFontDatabase::applicationFontFamilies(fontId);
    if(fontFamilies.size() > 0) {
        m_Font.setFamily(fontFamilies[0]);
    }else {
        m_Font.setFamily("黑体");
    }
    updateDraw();
    return true;
}

QPointF GY_GraphicsWideTextItem::precalculatedPosition()
{
    QPointF position = this->getCenterPointF();
    QPointF size = this->getEditPointF().value("Point");
    qreal addW = size.x()-position.x();
    qreal addH = size.y()-position.y();
    QPointF center(position.x()+addW/2,position.y()+addH/2);
    //!qAbs绝对值，两点矩形宽高
    qreal halfW = qAbs(addW/2);
    qreal halfH = qAbs(addH/2);
    QString align = m_PropertyInfoMap["Alignment"].propertyValue.value<QString>();
    QPointF point;
    QFontMetrics fm(m_Font);
    //!文字宽度
    int pixelsWide = fm.horizontalAdvance(m_PropertyInfoMap["DataString"].propertyValue.toString());
    //!文字高度
    int pixelsHigh = fm.capHeight();
    if(align == "LEFT") {
        point.setX(center.x()-halfW);
        point.setY(center.y()+halfH);
    }else if(align == "RIGHT") {
        point.setX(center.x()+halfW-pixelsWide);
        point.setY(center.y()+halfH);
    }else if(align == "CENTER") {
        point.setX(center.x()-pixelsWide/2);
        point.setY(center.y()+halfH);
    }else if(align == "MIDDLE_CENTER") {
        point.setX(center.x()-pixelsWide/2);
        point.setY(center.y()+pixelsHigh/2);
    }else if(align == "MIDDLE_LEFT") {
        point.setX(center.x()-halfW);
        point.setY(center.y()+pixelsHigh/2);
    }else if(align == "MIDDLE_RIGHT") {
        point.setX(center.x()+halfW-pixelsWide);
        point.setY(center.y()+pixelsHigh/2);
    }else if(align == "TOP_RIGHT") {
        point.setX(center.x()+halfW-pixelsWide);
        point.setY(center.y()-halfH+pixelsHigh);
    }else if(align == "TOP_LEFT") {
        point.setX(center.x()-halfW);
        point.setY(center.y()-halfH+pixelsHigh);
    }else if(align == "TOP_CENTER") {
        point.setX(center.x()-pixelsWide/2);
        point.setY(center.y()-halfH+pixelsHigh);
    }
    return point;
}




